<template>
    <div>
        <div class="breadcrumb-box">
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>意见反馈</el-breadcrumb-item>
                <el-breadcrumb-item>新增意见反馈</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="line">
            <img :src="$global.Image.icon_goods_line" />
        </div>
        <div class="container">
            <div class="line-ti">
                <div>新增意见反馈</div>
            </div>
            <!-- <div class="write-info-tit">
                填写意见反馈 信息
            </div> -->
            <div class="tishi">
                <!-- 尊敬的用户：<br> 您好！为了给您提供更好的服务，我们希望收集您使用时的看法或建议。对您的配合和支持表示衷心感谢！ -->
            </div>

            <el-form ref="form" :model="form" label-width="150px">
                <div class="form">
                    <el-form-item label="反馈类型：">
                        <el-select style="width: 584px;" v-model="form.feedback_type" placeholder="请选择">
                            <el-option v-for="(item,index) in typeList" :key="index" :label="item.name" :value="item.tag_id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="反馈内容：">
                        <el-input type="textarea" style="width: 584px;" v-model="form.content" placeholder="请输入您要反馈的内容"></el-input>
                    </el-form-item>
                    <el-form-item label="上传图片：">
                        <el-upload
                            action="http://gongchangguanjia.3todo.com/api/article/upload"
                            accept="image/png,image/jpeg,image/jpg"
                            :on-success="handleAvatarSuccess"
                            :multiple="true"
                            name="files[]"
                            list-type="picture-card">
                            <i class="el-icon-plus"></i>
                        </el-upload>
                    </el-form-item>
                </div>
                <el-form-item>
                    <el-button type="primary" @click="publish">提交</el-button>
                </el-form-item>

            </el-form>
        </div>
    </div>
</template>

<script>
import { artFeedback, artIclePublish, uploadFile } from "@api/user";
export default {
    data() {
        return {
            form: {
                content: "",
                feedback_type: "",
                files: [],
                type:7
            },
            
            headers: {
                "Authori-zation": "",
            },
            typeList: [],
        };
    },
    mounted() {
        this.getTypeList();
        this.headers = {
            "Authori-zation": "Bearer " + localStorage.getItem("token"),
        };
    },
    methods: {
        handleAvatarSuccess(res, file,fileList) {
            this.form.files = this.form.files.concat(res.data[0])
        },
        publish() {
            let data = this.form;
            if(!data.content){
                return this.$message("请输入内容");
            }
            if(!data.feedback_type){
                return this.$message("请选择反馈类型");
            }
            if(!data.files.length){
                return this.$message("请上传图片");
            }
            data.files = JSON.stringify(data.files);
            artIclePublish(data)
                .then((res) => {
                    if (res.status == 200) {
                        this.$message("提交成功");
                        setTimeout(() => {
                            this.$router.go(-1)
                        }, 1500);
                        return;
                    }
                    this.$message(res.msg);
                })
                .catch((err) => {
                    console.log(err);
                    this.$message(err);
                });
        },
        getTypeList() {
            artFeedback()
                .then((res) => {
                    console.log(res);
                    this.typeList = res.data;
                })
                .catch((err) => {
                    console.log(err);
                });
        },
    },
};
</script>

<style >
      .el-textarea__inner{
        height: 151px !important;
        resize: none;
    }
</style>

<style scoped  lang="scss">
.upload-list {
    img {
        width: 88px;
        height: 88px;
        margin-right: 44px;
    }
}
.upload {
    position: relative;
    width: 88px;
    img {
        width: 88px;
        height: 88px;
    }
    .file-upload {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        opacity: 0;
        width: 88px;
        height: 88px;
    }
}
.line {
    width: 1200px;
    margin: 0 auto 30px;
    img {
        display: block;
        width: 100%;
    }
}
.form {
    padding: 30px 0 25px;
    background: #fffbfb;
    box-sizing: border-box;
}
.tishi {
    font-size: 16px;
    text-align: left;
    color: #333333;
    line-height: 32px;
    margin: 16px 0;
}
.el-upload--picture-card {
    width: 88px;
    height: 88px;
    line-height: 88px;
}
.el-upload-list--picture-card .el-upload-list__item {
    width: 88px;
    height: 88px;
}
.file {
    width: 520px;
    background: #ffffff;
    border-radius: 5px;
    box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    padding: 10px 25px;
    box-sizing: border-box;
    .file-left {
        font-size: 16px;
        font-weight: bold;
        text-align: left;
        color: #333333;
        // line-height: 16px;
        // display: inline-block;
    }
    .file-right {
        flex: 1;
        display: flex;
        align-items: center;
        .no-file {
            font-size: 13px;
            color: #999999;
            margin-right: 10px;
        }
        .have-file {
            font-size: 13px;
            color: #333333;
            margin-right: 10px;
        }
        .choose-file {
            width: 88px;
            height: 24px;
            background: #e2edff;
            border: 1px solid #13479d;
            border-radius: 2px;
            font-size: 12px;
            text-align: center;
            color: #13479d;
            line-height: 24px;
            cursor: pointer;
        }
    }
}
.el-button--primary:focus,
.el-button--primary:hover {
    background: #da213d;
    border-color: #da213d;
}
.el-button--primary {
    width: 230px;
    background: #da213d;
    border-radius: 5px;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    color: #ffffff;
    line-height: 18px;
    box-sizing: border-box;
    height: 50px;
    border-color: #da213d;
    &:hover {
        background: #da213d;
        border-color: #da213d;
    }
    &:active {
        background: #da213d;
        border-color: #da213d;
    }
}
.el-input {
    width: 520px;
    border-radius: 2px;
    input {
        box-shadow: 0px 1px 3px 2px rgba(0, 0, 0, 0.07) inset;
    }
}
.el-form-item {
    margin-top: 20px;
}
.el-form-item__label {
    text-align: right;
    font-size: 15px;
    // font-weight: bold;
    padding-left: 25px;
}
.el-textarea {
    border-radius: 2px;
    height: 151px;
    textarea {
        height: 151px;
        box-shadow: 0px 1px 3px 2px rgba(0, 0, 0, 0.07) inset;
    }
}

.write-info-tit {
    position: relative;
    font-size: 18px;
    font-weight: bold;
    height: 90px;
    padding-left: 24px;
    display: flex;
    align-items: center;
    color: #333333;
    border-bottom: 1px dashed #eaecfa;
    &::before {
        border-radius: 100%;
        border: 3px solid #da213d;
        position: absolute;
        width: 5px;
        height: 5px;
        left: 0;
        top: 0;
        bottom: 0;
        margin: auto 0;
        content: "";
    }
}
.line-ti {
    width: 100%;
    border-bottom: 1px solid #dbdbdb;
    display: flex;
    > div {
        color: #da213d;
        font-size: 18px;
        // border-bottom: 3px solid $color;
        // width: 112px;
        line-height: 36px;
        font-weight: bold;
        position: relative;
        &::before {
            position: absolute;
            bottom: 0;
            left: 0;
            content: "";
            width: 72px;
            height: 3px;
            background: #da213d;
        }
    }
}
</style>